package com.iot.web.controller.device;

import java.util.HashSet;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.iot.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iot.common.annotation.Log;
import com.iot.common.core.controller.BaseController;
import com.iot.common.core.domain.AjaxResult;
import com.iot.common.enums.BusinessType;
import com.iot.device.domain.QuakeClient;
import com.iot.device.service.IQuakeClientService;
import com.iot.common.utils.poi.ExcelUtil;
import com.iot.common.core.page.TableDataInfo;

/**
 * 震动监测设备Controller
 * 
 * @author iot
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/device/quakeClient")
public class QuakeClientController extends BaseController
{
    @Autowired
    private IQuakeClientService quakeClientService;

    /**
     * 查询震动监测设备列表
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuakeClient quakeClient)
    {
        startPage();
        if(!SecurityUtils.isAdmin() && quakeClient.getUserId() == null){
            quakeClient.setOrgId(SecurityUtils.getDeptId());
        }
        List<QuakeClient> list = quakeClientService.selectQuakeClientList(quakeClient);
        return getDataTable(list);
    }

    /**
     * 导出震动监测设备列表
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:export')")
    @Log(title = "震动监测设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuakeClient quakeClient)
    {
        if(!SecurityUtils.isAdmin() && quakeClient.getUserId() == null){
            quakeClient.setOrgId(SecurityUtils.getDeptId());
        }
        List<QuakeClient> list = quakeClientService.selectQuakeClientList(quakeClient);
        ExcelUtil<QuakeClient> util = new ExcelUtil<QuakeClient>(QuakeClient.class);
        util.exportExcel(response, list, "震动监测设备数据");
    }

    /**
     * 获取震动监测设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(quakeClientService.selectQuakeClientById(id));
    }

    /**
     * 新增震动监测设备
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:add')")
    @Log(title = "震动监测设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuakeClient quakeClient)
    {
        return toAjax(quakeClientService.insertQuakeClient(quakeClient));
    }

    /**
     * 修改震动监测设备
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:edit')")
    @Log(title = "震动监测设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuakeClient quakeClient)
    {
        return toAjax(quakeClientService.updateQuakeClient(quakeClient));
    }

    /**
     * 删除震动监测设备
     */
    @PreAuthorize("@ss.hasPermi('device:quakeClient:remove')")
    @Log(title = "震动监测设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quakeClientService.deleteQuakeClientByIds(ids));
    }
}
